import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		/**
		 * 是否需要强制登录
		 */
		forcedLogin: true,
		hasLogin: false,
		userName: "",
		token: "",
		inviteCode:""
	},
	mutations: {
		login(state, userName) {
			state.userName = userName || '新用户';
			state.hasLogin = true;
		},
		logout(state) {  //退出登录
			state.userName = "";
			state.hasLogin = true;
			uni.removeStorage({  //退出登录清空本地信息
                key: 'token'  
            })  
		},
		token(state, token) { //登录
			state.token = token;
			state.hasLogin = true;
			uni.setStorage({//将用户信息保存在本地  
                key: 'token',  
                data: token  
            })
		},
		inviteCode(state,inviteCode){
			state.inviteCode = inviteCode;
			
			uni.setStorage({//将用户信息保存在本地  
                key: 'inviteCode',  
                data: inviteCode  
            })
		}
	}
})

export default store
